package com.push.web.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.push.web.service.IBizAIAssistantService;
import com.push.web.utils.ApiRequest;
import com.push.web.utils.CommonUtil;
import org.springframework.stereotype.Service;

@Service
public class IBizAIAssistantServiceImpl implements IBizAIAssistantService {
    private ApiRequest apiRequest = new ApiRequest();

    @Override
    public JSONObject extractInfo(JSONObject jsonObject)
    {
        String prompt = jsonObject.getString("content") + jsonObject.getString("askfor");
        jsonObject.put("prompt",prompt);
        return apiCallRemoteService(jsonObject);
    }
    public JSONObject apiCallRemoteService(JSONObject jsonObject){
        JSONObject retObj = new JSONObject();
        JSONObject tmpObj = new JSONObject();
        tmpObj.put("example","false");
        tmpObj.put("api_key","");
//        tmpObj.put("api_key", "sk-cIie3TGlVBwqLHZc7022D4247c2d406b999dDfCb072f9749");
        tmpObj.put("prompt", jsonObject.getString("prompt"));

        //调用信息抽取接口
        String TRANSFER_ORDER_API = "";
//        String TRANSFER_ORDER_API = "http://101.35.155.58:8088/ask_gpt";
        System.out.println("调用远程AI接口：" + TRANSFER_ORDER_API);
        try{
            JSONObject result = apiRequest.goPost(TRANSFER_ORDER_API,tmpObj);
            JSONObject jsonObj = CommonUtil.stringToJSONObject(result.getString("result"));
            result.put("result",jsonObj);
            System.out.println("成功调用远程AI服务接口2goPost：" + result);
            retObj = result;
        }catch (Exception e){
            System.out.println("调用远程AI信息抽取接口失败！");
            e.printStackTrace();
        }
        return retObj;
    }
}
